///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include <time.h>
#include <string>
#include "timestamp.h"
#include "stringutil.h"

Timestamp::Timestamp() { }

std::string Timestamp::getTime() {
	char buf2[4096];
	time_t rawTime;
    struct tm* timeInfo;
 	
	time ( &rawTime );
    timeInfo = localtime ( &rawTime );
    strftime( buf2, 4096, "%X", timeInfo );
    
    return std::string(buf2);
}

std::string Timestamp::getDateTime() {
	char buf2[4096];
	time_t rawTime;
    struct tm* timeInfo;
 	
	time ( &rawTime );
    timeInfo = localtime ( &rawTime );
    strftime( buf2, 4096, "%X on %b %d %Y", timeInfo );
    
    return std::string(buf2);
}

std::string Timestamp::backupTime() {
	char buf2[4096];
	time_t rawTime;
    struct tm* timeInfo;
 	
	time ( &rawTime );
	timeInfo = localtime ( &rawTime );
	strftime( buf2, 4096, "%Y-%m-%d", timeInfo );

    return std::string(buf2);
}

unsigned Timestamp::random( const unsigned& a ) {
	return ( rand() % a );
}

unsigned Timestamp::random( const unsigned& a, const unsigned& b ) {
	return ( rand() % ( b - a ) + a );
}

bool Timestamp::chance( const unsigned& a ) {
	if ( !a )
		return false;
	if ( a > 99 )
		return true;
	return ( a > (unsigned)( rand() % 100 ) );
}
